package com.example.demo.Controller;

import com.example.demo.Service.DishesService;
import com.example.demo.repository.domain.Dishes;
import com.example.demo.util.Verlify;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author ZhangKe
 * @Description
 * @date 2019/7/4 12:35.
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/dishes")
public class DishesController {

    @Autowired
    private Verlify verlify;

    @Autowired
    private DishesService dishesService;

    @PostMapping("/insert")
    public int insertMenu(@RequestParam(value = "name")String name,
                          @RequestParam(value = "price",required = false,defaultValue = "10.0")float price,
                          @RequestParam(value = "type",required = false,defaultValue = "素菜")Integer type,
                          @RequestParam(value = "picture",required = false,defaultValue = "img/chaofan1.jpg")String picture){
            Dishes dishes =new Dishes();
            dishes.setDishName(name);
            dishes.setDishPrice(price);
            dishes.setDishTypeNumber(type);
            dishes.setDishPicture(picture);
            return dishesService.insert(dishes);
    }

    @GetMapping("/list")
    public List<Dishes> getByName(@RequestParam(value = "name",required = false)String name,
                                  @RequestParam(value = "type",required = false,defaultValue = "0")Integer type){
        return dishesService.searchAll(name,type);
    }
}
